package com.lemon.smartsafetynew.ui.adapter.ledger;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.event.work.WorkUIEvent;
import com.lemon.smartsafetynew.entity.ledger.LedgerPanelButton;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/8/14.
 */

public class LedgerHomeAdapter extends LemonRcvAdapter<LedgerPanelButton> {

    private RecyclerTClickListener<LedgerPanelButton> mListener;

    public LedgerHomeAdapter(@Nullable List<LedgerPanelButton> data,
                                RecyclerTClickListener<LedgerPanelButton> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new LedgerItem();
    }

    private class LedgerItem implements AdapterItem<LedgerPanelButton> {

        private LinearLayout ripple;
        private ImageView iconImage;
        private TextView textView;

        private int mPosition;
        private LedgerPanelButton mData;

        @Override
        public int getLayoutResId() {
            return R.layout.item_main_panel_new;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            iconImage = (ImageView) root.findViewById(R.id.label_icon);
            textView = (TextView) root.findViewById(R.id.label_name);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(LedgerPanelButton ledgerPanelButton, int position) {

            mData = ledgerPanelButton;
            mPosition = position;
            iconImage.setImageResource(ledgerPanelButton.getIconRes());
            textView.setText(ledgerPanelButton.getTitleRes());

        }
    }
}
